package hongvt.quanlynhanvien;

import hongvt.quanlynhanvien.utils.SharedPreferencesManager;
import android.app.ActionBar;
import android.app.Activity;
import android.app.ActivityGroup;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Toast;
import butterknife.ButterKnife;

public abstract class AbstractActivity extends ActivityGroup {

	protected Activity context;
	protected SharedPreferencesManager sharedPref;

	// protected SimpleFacebook mSimpleFacebook;

	@Override
	protected void onCreate(Bundle arg0) {
		// TODO Auto-generated method stub
		super.onCreate(arg0);

		// Thread.setDefaultUncaughtExceptionHandler(new
		// ExceptionHandler(this));

		// requestWindowFeature(Window.FEATURE_NO_TITLE);
		// getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
		// WindowManager.LayoutParams.FLAG_FULLSCREEN);
		try {
			ActionBar bar = getActionBar();
			// for color
			bar.setBackgroundDrawable(new ColorDrawable(Color
					.parseColor("#00C4CD")));
		} catch (Exception e) {
			// TODO: handle exception
		}

		context = this;
		this.sharedPref = SharedPreferencesManager.getInstance(context);

		setContentView(getCurrentViewId());

		ButterKnife.inject(this);

		this.afterInitView();

	}

	protected abstract int getCurrentViewId();

	protected abstract void afterInitView();

	// protected abstract int getTitleStringId();

	protected void showToast(String message) {
		Toast.makeText(context, message, Toast.LENGTH_LONG).show();
	}

	protected void showToast(int resourceStrigId) {
		showToast(getString(resourceStrigId));
	}

	protected void showView(View view) {
		view.setVisibility(View.VISIBLE);
	}

	protected void invisibleView(View view) {
		view.setVisibility(View.INVISIBLE);
	}

	protected void hideView(View view) {
		view.setVisibility(View.GONE);
	}

	/**
	 * get view from layout resource
	 * 
	 * @param layoutId
	 *            layout resource id
	 * @return view
	 */
	public View getView(int layoutId) {
		LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View view = inflater.inflate(layoutId, null, false);
		return view;
	}

}
